package br.com.tcf.coverters;

import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.tcf.dao.DiaSemanaDao;
import br.com.tcf.entidades.DiaSemana;

@FacesConverter("diaSemanaConverter")  
public class DiaSemanaConverter implements Converter{
	public List<DiaSemana> dias;  
	DiaSemanaDao dao = new DiaSemanaDao();  

	public DiaSemanaConverter(){  
		dias = dao.buscaDiaSemana();
	}  

	@Override
	public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) {
		if (value != null && !value.isEmpty()) {
			return (DiaSemana) uiComponent.getAttributes().get(value);
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
		if (value instanceof DiaSemana) {
			DiaSemana entity= (DiaSemana) value;
			if (entity != null && entity instanceof DiaSemana && entity.getId_dia_semana() != null) {
				uiComponent.getAttributes().put( entity.getId_dia_semana().toString(), entity);
				return entity.getId_dia_semana().toString();
			}
		}
		return "";
	}
}